{extends 'admin/layout/table-main.tpl'}

{block title}渠道数据统计{/block}
{block smallTitle}系统内的渠道管理。{/block}

{block main}
<div class="ibox float-e-margins">
	<div class="ibox-content">
		<div class="row row-lg">
			<div class="col-sm-12">
				<!-- Example Events -->
				<div class="example-wrap">
					<h4 class="example-title">{block title}{/block}</h4>
					<div class="example">
						<div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
							<form method="get" action="">
								<span>地区：</span>
								<select class="medium m-wrap" tabindex="1"
										name="province_id" id="province">
									<option value="" >省/市</option>
									{foreach $province as $item}
										<option value="{$item.id}" {if $get.province_id==$item.id}selected="selected"{/if}>{$item.name}</option>
									{/foreach}
								</select>&nbsp;&nbsp;<select class="medium m-wrap" tabindex="1"
															 name="city_id" id="town" {if !$city}style="display:none;"{/if}>
									<option value="" >市/地区</option>
									{foreach $city as $item}
										<option value="{$item.id}" {if $get.city_id==$item.id}selected="selected"{/if}>{$item.name}</option>
									{/foreach}
								</select>&nbsp;&nbsp;<select class="medium m-wrap" tabindex="1"
															 name="area_id" id="area" {if !$area}style="display:none;{/if}">
									<option value="" >县/市</option>
									{foreach $area as $item}
										<option value="{$item.id}" {if $get.area_id==$item.id}selected="selected"{/if}>{$item.name}</option>
									{/foreach}
								</select>
								&nbsp;&nbsp;
								<span>时间：</span>
								<input type="text" id="start_at" name="start_at" value="{$get.start_at}" class="m-wrap date-range" onclick="WdatePicker({ dateFmt:'yyyy-MM-dd',maxDate:'#F{ $dp.$D(\'end_at\')}'})" value="2015-10-28">
								-
								<input type="text" id="end_at" name="end_at" value="{$get.end_at}" onclick="WdatePicker({ dateFmt:'yyyy-MM-dd',minDate:'#F{ $dp.$D(\'start_at\')}'})" value="2015-10-28" class="m-wrap date-range">

								</br></br>
								<button class="btn btn-white " type="button" id="openedit" data-url="{route('AdminSourceGetAll')}">
									<i class="fa  fa-bar-chart"></i>
									渠道
								</button>
								<span id="citybox">
									{foreach $channel as $item}
										<a href="javascript:;" id="city_{$item.id}"> {$item.name} <input type="hidden" name="channel_ids[]" value="{$item.id}"></a>
									{/foreach}
								</span>
								&nbsp;&nbsp;
								<button class="btn btn-white " type="submit">
									<i class="fa fa-search"></i>
									搜索
								</button>
								<a type="button" class="btn btn-outline btn-default" href="{route('AdminSourceStatisticsExcel',$get)}">
									<i class="glyphicon glyphicon-plus" aria-hidden="true"></i> 导出
								</a>
							</form>
						</div>
						<table id="exampleTablePagination" data-toggle="table" data-mobile-responsive="true">
							<thead>
							<tr>
								{*<th data-field="state" data-checkbox="false"></th>*}
								<th data-field="id">渠道</th>
								<th data-field="order">订单数</th>
								<th data-field="complate_count">实际交易数</th>
								<th data-field="cancel_count">取消定单数</th>
								<th data-field="deny_count">拒签数</th>
								<th data-field="complate">实际交易比率</th>
								<th data-field="cancel">取消定单比率</th>
								<th data-field="deny">拒签比率</th>
							</tr>
							</thead>
							<tbody>
							{foreach $data as $item}
								<tr data-id="{$item.id}" data-name="{$item.name|escape}" data-type="admin" >
									<td>{$item.channel_name}</td>
									<td>{$item.order_count}</td>
									<td>{$item.complate_count}</td>
									<td>{$item.canceled_count}</td>
									<td>{$item.deny_count}</td>
									<td>{$item.complate}%</td>
									<td>{$item.canceled}%</td>
									<td>{$item.deny}%</td>
								</tr>
							{/foreach}
							</tbody>
						</table>
					</div>
				</div>
				<!-- End Example Events -->
			</div>
		</div>
	</div>
</div>
{/block}

{block script}
	<script type="text/javascript">
		$(document).ready(function() {
			$('#province').change(function() {
				var provinceID = $(this).children('option:selected').val(); //这就是selected的值
				if (provinceID > 0) {
					tmp = '<option value="">市/地区<\/option>';
					$.ajax({
						type: "GET",
						url: "{route('AdminGlobalLocationData')}",
						data: "pid="+provinceID,
						success: function(result){
							$.each(result['data'], function(key, val) {
								tmp += '<option value="' + val.id + '" >' + val.name + '<\/option>';
							});
							$('#town').html(tmp).show();
							$('#area').html('').hide();
							tmp = '';
						}
					});
				} else {
					$('#town').html('').hide();
					$('#area').html('').hide();
				}
			});

			$('#town').change(function() {
				var townID = $(this).children('option:selected').val(); //这就是selected的值
				if (townID > 0) {
					tmp = '<option value="">县/市<\/option>';
					$.ajax({
						type: "GET",
						url: "{route('AdminGlobalLocationData')}",
						data: "pid="+townID,
						success: function(result){
							$.each(result['data'], function(key, val) {
								tmp += '<option value="' + val.id + '" >' + val.name + '<\/option>';
							});
							$('#area').html(tmp).show();
							tmp = '';
						}
					});
				} else {
					$('#area').html('').hide();
				}
			});
		});
	</script>
	<script src="{asset('admin/js/plugins/layer/layer.min.js')}"></script>
	<script>
		$(document).ready(function(){
			$('#openedit').click(function(){
				var url = $(this).attr('data-url');
				layer.open({
					type: 2,
					title: false,
					shadeClose: false,
					shade: 0.8,
					area: ['800px', '400px'],
					content: url
				});
			});
		})
	</script>
{/block}
